#ifndef __MESH_H__
#define __MESH_H__

#include "../../Header/Header.h"
#include "../Vertex.h"
#include "../Shader.h"
#include "Resource.h"

class Mesh : public Resource
{
protected:
	Vertex* m_Vertices;
	GLushort* m_Indices;
	GLuint m_iIndices;
	GLuint m_iVertices;
	GLuint m_VBO;
	GLuint m_IBO;
protected:
	//Generate array buffer
	//Binding vertices data and indices data into vRam
	virtual void Load();
	virtual ~Mesh();
	friend class ResourceBank;
	friend class ResourceManagement;
public:
	Mesh(bool bIsKilledAfterUnUse = true);

	//Overload when need
	//Initialize mesh resources once time

	//Load vertices data from model specification file
	//You can mod here, now it support only nfg
	virtual GLint Init(char* strFileModel, char* strFileType);
	virtual GLint Init(GLuint iVertices, Vertex* Vertices, GLuint iIndices, GLushort* Indices);

	//Binding to data buffer
	virtual void Render(const Shader* sha);

	//release
	virtual void Unrender();

	//Increase user count when it has reference
	virtual Mesh* Reference();

	//Decrease user count when it has dereference
	//if user count down to 0,
	//this method will delete buffer data
	//and set loadins flag = false
	//if isKilledAfterUnUse = false all data will release.
	virtual void Dereference();

	virtual int GetVertexCount(){ return m_iVertices; }
	virtual int GetIndexCount(){ return m_iIndices; }
	virtual Vertex* GetVertices(){ if (m_Vertices) return m_Vertices; return 0; }
};

#endif